package programme;


public class CrazyThreads1 implements Runnable {

	volatile boolean alive;
	volatile int i;
	
	
	@Override
	public void run() {
		System.out.println("Thread starten...");
		
		i = 0;
		alive = true;
		
		while(true){
			if(alive){
				i++;
			} else {
				break;
			}
				
		}
		System.out.println("Thread stoppet!");
	}
	
	public static void main(String[] args) {
		CrazyThreads1 c= new CrazyThreads1();
		
		new Thread(c).start();
		
		while (Thread.activeCount() > 1) {
			
			try {
				Thread.sleep(500);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			long iNow = c.i;
			System.out.println(iNow);
			
			if(iNow >= LIMIT){
				c.alive = false;
				System.out.println("Thread gestoppt! (alive = " +c.alive + ")");
			}
		}

	}
	private static final long LIMIT = 100000000L;
}
